.class public Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;
.super Ljava/lang/Object;
.source "DownloadHandler.java"


# static fields
.field private static final TAG:Ljava/lang/String; = "DownloadHandler"

.field private static final mDownloadHandler:Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;


# instance fields
.field private final mDownloadsInProgress:Ljava/util/HashMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/HashMap",
            "<",
            "Ljava/lang/Long;",
            "Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;",
            ">;"
        }
    .end annotation
.end field

.field private final mDownloadsQueue:Ljava/util/LinkedHashMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/LinkedHashMap",
            "<",
            "Ljava/lang/Long;",
            "Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;",
            ">;"
        }
    .end annotation
.end field

.field private final mMaxConcurrentDownloadsAllowed:I


# direct methods
.method static constructor <clinit>()V
    .registers 1

    .prologue
    .line 32
    new-instance v0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;

    invoke-direct {v0}, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;-><init>()V

    sput-object v0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadHandler:Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;

    return-void
.end method

.method public constructor <init>()V
    .registers 2

    .prologue
    .line 27
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 30
    new-instance v0, Ljava/util/LinkedHashMap;

    invoke-direct {v0}, Ljava/util/LinkedHashMap;-><init>()V

    iput-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    .line 31
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    .line 36
    const/4 v0, 0x1

    iput v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mMaxConcurrentDownloadsAllowed:I

    return-void
.end method

.method public static getInstance()Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;
    .registers 1

    .prologue
    .line 39
    sget-object v0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadHandler:Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;

    return-object v0
.end method

.method private declared-synchronized startDownloadThread()V
    .registers 7

    .prologue
    .line 53
    monitor-enter p0

    :try_start_1
    iget-object v4, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-virtual {v4}, Ljava/util/LinkedHashMap;->keySet()Ljava/util/Set;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v3

    .line 54
    .local v3, "keys":Ljava/util/Iterator;, "Ljava/util/Iterator<Ljava/lang/Long;>;"
    new-instance v1, Ljava/util/ArrayList;

    invoke-direct {v1}, Ljava/util/ArrayList;-><init>()V

    .line 55
    .local v1, "ids":Ljava/util/ArrayList;, "Ljava/util/ArrayList<Ljava/lang/Long;>;"
    :goto_10
    iget-object v4, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    invoke-virtual {v4}, Ljava/util/HashMap;->size()I

    move-result v4

    const/4 v5, 0x1

    if-ge v4, v5, :cond_42

    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_42

    .line 56
    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Long;

    .line 57
    .local v0, "id":Ljava/lang/Long;
    iget-object v4, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-virtual {v4, v0}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;

    .line 58
    .local v2, "info":Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;
    invoke-virtual {v2}, Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;->startDownloadThread()V

    .line 59
    invoke-virtual {v1, v0}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    .line 60
    iget-object v4, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    iget-object v5, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-virtual {v5, v0}, Ljava/util/LinkedHashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v5

    invoke-virtual {v4, v0, v5}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_3e
    .catchall {:try_start_1 .. :try_end_3e} :catchall_3f

    goto :goto_10

    .line 53
    .end local v0    # "id":Ljava/lang/Long;
    .end local v1    # "ids":Ljava/util/ArrayList;, "Ljava/util/ArrayList<Ljava/lang/Long;>;"
    .end local v2    # "info":Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;
    .end local v3    # "keys":Ljava/util/Iterator;, "Ljava/util/Iterator<Ljava/lang/Long;>;"
    :catchall_3f
    move-exception v4

    monitor-exit p0

    throw v4

    .line 65
    .restart local v1    # "ids":Ljava/util/ArrayList;, "Ljava/util/ArrayList<Ljava/lang/Long;>;"
    .restart local v3    # "keys":Ljava/util/Iterator;, "Ljava/util/Iterator<Ljava/lang/Long;>;"
    :cond_42
    :try_start_42
    invoke-virtual {v1}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v4

    :goto_46
    invoke-interface {v4}, Ljava/util/Iterator;->hasNext()Z

    move-result v5

    if-eqz v5, :cond_58

    invoke-interface {v4}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Long;

    .line 66
    .restart local v0    # "id":Ljava/lang/Long;
    iget-object v5, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-virtual {v5, v0}, Ljava/util/LinkedHashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_57
    .catchall {:try_start_42 .. :try_end_57} :catchall_3f

    goto :goto_46

    .line 68
    .end local v0    # "id":Ljava/lang/Long;
    :cond_58
    monitor-exit p0

    return-void
.end method


# virtual methods
.method public declared-synchronized WaitUntilDownloadsTerminate()V
    .registers 3
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/InterruptedException;
        }
    .end annotation

    .prologue
    .line 89
    monitor-enter p0

    :try_start_1
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    invoke-virtual {v0}, Ljava/util/HashMap;->size()I

    move-result v0

    if-nez v0, :cond_13

    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-virtual {v0}, Ljava/util/LinkedHashMap;->size()I
    :try_end_e
    .catchall {:try_start_1 .. :try_end_e} :catchall_19

    move-result v0

    if-nez v0, :cond_13

    .line 108
    :goto_11
    monitor-exit p0

    return-void

    .line 107
    :cond_13
    const-wide/16 v0, 0x1388

    :try_start_15
    invoke-virtual {p0, v0, v1}, Ljava/lang/Object;->wait(J)V
    :try_end_18
    .catchall {:try_start_15 .. :try_end_18} :catchall_19

    goto :goto_11

    .line 89
    :catchall_19
    move-exception v0

    monitor-exit p0

    throw v0
.end method

.method public declared-synchronized dequeueDownload(J)V
    .registers 6
    .param p1, "mId"    # J

    .prologue
    .line 75
    monitor-enter p0

    :try_start_1
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    invoke-static {p1, p2}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/util/HashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 76
    invoke-direct {p0}, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->startDownloadThread()V

    .line 77
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    invoke-virtual {v0}, Ljava/util/HashMap;->size()I

    move-result v0

    if-nez v0, :cond_20

    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-virtual {v0}, Ljava/util/LinkedHashMap;->size()I

    move-result v0

    if-nez v0, :cond_20

    .line 78
    invoke-virtual {p0}, Ljava/lang/Object;->notifyAll()V
    :try_end_20
    .catchall {:try_start_1 .. :try_end_20} :catchall_22

    .line 80
    :cond_20
    monitor-exit p0

    return-void

    .line 75
    :catchall_22
    move-exception v0

    monitor-exit p0

    throw v0
.end method

.method public declared-synchronized dequeueWaitDownload(J)V
    .registers 6
    .param p1, "id"    # J

    .prologue
    .line 83
    monitor-enter p0

    :try_start_1
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-static {p1, p2}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/util/LinkedHashMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_a
    .catchall {:try_start_1 .. :try_end_a} :catchall_c

    .line 84
    monitor-exit p0

    return-void

    .line 83
    :catchall_c
    move-exception v0

    monitor-exit p0

    throw v0
.end method

.method declared-synchronized enqueueDownload(Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;)V
    .registers 6
    .param p1, "info"    # Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;

    .prologue
    .line 43
    monitor-enter p0

    :try_start_1
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    iget-wide v2, p1, Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;->mId:J

    invoke-static {v2, v3}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/util/LinkedHashMap;->containsKey(Ljava/lang/Object;)Z

    move-result v0

    if-nez v0, :cond_1d

    .line 47
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    iget-wide v2, p1, Lcom/zuimeia/sdk/download/providers/downloads/DownloadInfo;->mId:J

    invoke-static {v2, v3}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-virtual {v0, v1, p1}, Ljava/util/LinkedHashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 48
    invoke-direct {p0}, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->startDownloadThread()V
    :try_end_1d
    .catchall {:try_start_1 .. :try_end_1d} :catchall_1f

    .line 50
    :cond_1d
    monitor-exit p0

    return-void

    .line 43
    :catchall_1f
    move-exception v0

    monitor-exit p0

    throw v0
.end method

.method public declared-synchronized hasDownloadInQueue(J)Z
    .registers 6
    .param p1, "id"    # J

    .prologue
    .line 71
    monitor-enter p0

    :try_start_1
    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsQueue:Ljava/util/LinkedHashMap;

    invoke-static {p1, p2}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/util/LinkedHashMap;->containsKey(Ljava/lang/Object;)Z

    move-result v0

    if-nez v0, :cond_19

    iget-object v0, p0, Lcom/zuimeia/sdk/download/providers/downloads/DownloadHandler;->mDownloadsInProgress:Ljava/util/HashMap;

    invoke-static {p1, p2}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/util/HashMap;->containsKey(Ljava/lang/Object;)Z
    :try_end_16
    .catchall {:try_start_1 .. :try_end_16} :catchall_1e

    move-result v0

    if-eqz v0, :cond_1c

    :cond_19
    const/4 v0, 0x1

    :goto_1a
    monitor-exit p0

    return v0

    :cond_1c
    const/4 v0, 0x0

    goto :goto_1a

    :catchall_1e
    move-exception v0

    monitor-exit p0

    throw v0
.end method
